using System.ComponentModel;
using System.Web.UI;
using CapDes.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using PS.WebParts.Rollup.GridViewWebPart;

namespace PS.WebParts
{
    public class DataWebPartBase
        : AjaxBasePart
        , IDataWebPart
    {
        private string dataSourcesString = Constants.DataSourceString;

        protected DataSourceCollection dataSources = new DataSourceCollection();

        [
            WebPartStorage(Storage.Shared),
            DefaultValue(Constants.DataSourceString),
            Browsable(false)
        ]
        public string DataSourcesString
        {
            get { return dataSourcesString; }
            set { dataSourcesString = value; }
        }

        protected DataSourceCollection DataSources
        {
            get
            {
                Page page = new Page();
                page.AppRelativeVirtualPath = "~/current.aspx";
                if (!string.IsNullOrEmpty(DataSourcesString))
                {
                    foreach (DataSourceControl source in page.ParseControl(DataSourcesString).Controls)
                    {
                        dataSources.Add(source);
                    }
                }
                return dataSources;
            }
        }
    }
}
